package com.marchsoft.musicalstore.repository;

import com.marchsoft.musicalstore.entity.SelfTodayClass;
import com.marchsoft.musicalstore.entity.StuCourse;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import javax.xml.crypto.Data;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 源
 * Date: 2019-11-17
 * Time: 11:22
 */
public interface StuCourseRepository extends JpaRepository<StuCourse,Integer> {

     //查询个人课表信息
     List <StuCourse> findById(int id);

     //查询个人当前日课程信息
     List<StuCourse> findByIdAndPickClassData(int id, Data PickClassData);


     /**
      * 源根据学生id和课程id查询该课
      * @param stuId
      * @param pickClaId
      * @return
      */
     List<StuCourse> findByStuIdAndPickClassId(Integer stuId,Integer pickClaId);

     /**
      * 根据学生id和课程类型以及现在时间查询学生的今日课程
      * @param stuId
      * @param ctype
      * @param week
      * @return
      */
     @Query(value = "select stu.pick_classid AS id,u.name As name,cor.name AS courseTypeName,stu.pick_class_time AS classTime,sel.class_hour AS sumClassTime,sel.name AS courseName,stu.class_hour AS leftTime," +
             "sel.limit_peonum As limitNum,sel.pass_peonum passNum from stucourse stu,coursetype cor,selclassable sel,user u where " +
             "stu_id=:stuId and stu.pick_classid=sel.id and cor.id=sel.course_id and sel.teacher_id=u.id and cor.type=:ctype and sel.weekday=:week",nativeQuery=true)
     List<SelfTodayClass> queryAllByClassType(@Param("stuId") int stuId,@Param("ctype") int ctype,@Param("week") int week);


}
